Skip to content

Top reddit#3

Merged
Verper1 merged 4 commits intomainfrom
top_reddit
Apr 11, 2026
Merged

Top reddit#3
Verper1 merged 4 commits intomainfrom
top_reddit

Conversation

@Verper1
Copy link
Copy Markdown
Owner

@Verper1 Verper1 commented Mar 18, 2026

No description provided.


time.sleep(1)

if created_utc >= before:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя тут буквально написано: «остановиться, если самый старый пост на странице новее текущего момента»
Ты не остановишься, выйдя за пределы трех дней и будешь постоянно листать назад
Правильно

created_utc < after



def main() -> None:
subreddit = "python"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты захардкодил название сабреддита, а по заданию его должен ввести пользователь

continue

for c in comments:
if c["kind"] != "t1":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо бы рекурсивно вытаскивать реплаи на комментарий

return int((datetime.now(timezone.utc) - timedelta(days=days_ago)).timestamp())


def fetch_posts(subreddit: str, after: int, before: int) -> list[dict[str, any]]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any - это встроенная функция питона, а Any - это тип


def get_utc_timestamp(days_ago: int) -> int:
"""Возвращает UTC timestamp n дней назад (timezone-aware)."""
from datetime import timezone
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тебе второй импорт timezone?

top_posters = Counter(post_authors).most_common(10)

# 3. ВСЕ ПОСТЫ
all_posts = posts
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем ты присваиваешь переменной новое имя без изменения содержимого?

if last_fullname:
params["after"] = last_fullname

response = requests.get(url, headers=HEADERS, params=params, timeout=10)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

запрос без обработки ошибок - опасное занятие

"""Собираем все посты за промежуток времени через JSON сабреддита."""
all_posts = []
url = f"https://www.reddit.com/r/{subreddit}/new.json"
params = {"limit": 100}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выноси подобные константные значения наверх в глобальный скоп
LIMIT = 100

if author and author != "[deleted]":
all_comments.append({"author": author, "created_utc": comment["created_utc"]})

time.sleep(0.5)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

константа


# 1. ТОП КОММЕНТАТОРОВ
comment_authors = [c["author"] for c in comments]
top_commenters = Counter(comment_authors).most_common(10)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

константа

@Verper1 Verper1 merged commit 1a7a48b into main Apr 11, 2026
@Verper1 Verper1 deleted the top_reddit branch April 11, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants